<?php
namespace app\walletyhbbadmin\controller;
use Think\Db;
// use Think\request;
require_once (APP_PATH .'api/FinanceApi.php');
class Certification extends AdminBase {


	public function index(){
		//查询分类表
		$list = Db::name('app_bank_config')->order('id desc')->paginate(10,false,['query'=>input()]);
		    	$page = $list->render();
		    	$this->assign('page',$page);//分页
		    	$this->assign('list',$list);// 赋值数据集

		return $this->fetch();
	}


	public function addBank(){
		if(IS_POST){
			//接收分类名称
			$bank['name']=input('name');
			if(!$bank['name']){
				$this->error('银行名称不能为空');
			}

			$file = request()->file('logo');
	        if(!empty($file)){
	            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads' );
	            $bank['logo'] = '/public/uploads/' . str_replace('\\', '/', $info->getsaveName());
	        }else{
	        	$this->error('银行logo不能为空');
	        }

			$bank['status']=input('status');
			$res=Db::name('app_bank_config')->insert($bank);
			if($res){
				$this->success('添加成功');
			}else{
				$this->error('添加失败');
			}
		}else{
			return $this->fetch();
		}
	}

	public function delBank(){
		//获取id
		$id=input('id');
	

		$res=Db::name('app_bank_config')->where('id',$id)->delete();
		if($res){
			$data['info']='删除成功';
			$data['status']='1';
			return json($data);
		}else{
			$data['info']='删除失败';
			$data['status']='-1';
			return json($data);
		}
	}

	public function updateStatus(){
		//获取id
		$id=input('id');
		//获取的状态值
		$status['status']=input('status');
		$res=Db::name('app_bank_config')->where(array('id'=>$id))->update($status);
		if($res){
			$this->success('修改成功');
		}else{
			$this->error('系统繁忙,请稍后重试');
		}
	}

	public function updateBank(){
		if(IS_POST){
			//接收分类名称
			$bank['name']=input('name');
			if(!$bank['name']){
				$this->error('银行名称不能为空');
			}

			$file = request()->file('logo');
	        if(!empty($file)){
	            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads' );
	            $bank['logo'] = '/public/uploads/' . str_replace('\\', '/', $info->getsaveName());
	        }
	        $where['id']=input('id');
			$bank['status']=input('status');
			$res=Db::name('app_bank_config')->where($where)->update($bank);
			if($res){
				$this->success('修改成功');
			}else{
				$this->error('修改失败');
			}
		}else{
			$id=input('id');
			$info=Db::name('app_bank_config')->where(array('id'=>$id))->find();
			$this->assign('info',$info);
			return $this->fetch();
		}
	}
}